<%@page language="java" session="true" pageEncoding="GBK"%>
<%@page import="ext.csc.component.numbergen.number.FormatedNumber"%>
<%@page import="ext.csc.component.numbergen.number.NumberGenerator"%>
<%@page import="ext.csc.component.numbergen.classification.ClassificationHelper"%>
<%@page import="ext.csc.component.numbergen.classification.Classification"%>
<%@page import="ext.csc.component.numbergen.rule.RuleInfoContained"%>
<%@page import="wt.session.SessionHelper"%>
<%@page import="java.util.ArrayList"%>
<%@page import="ext.csc.component.numbergen.bean.PropertiesBean"%>
<%@page import="ext.csc.component.numbergen.rule.GenerationRuleHelper"%>
<%@page import="ext.csc.component.numbergen.rule.FixLabelDefinition"%>
<%@page import="ext.csc.component.numbergen.bean.RequestInfoBean"%>

<%
	//Get selected classification path and number
	String parentClassPath = request.getParameter("parentPath");
	String fullClassPath = request.getParameter("fullPath");
	String generatedNumber = request.getParameter("gnumber");
	
	//Get classification object by path
	Classification classification = ClassificationHelper.getClassification(parentClassPath);
	classification.setObjectclassvalue(generatedNumber);
	
	PropertiesBean pb = new PropertiesBean();
	RequestInfoBean rb = new RequestInfoBean();
	
	//Set Request Bean
	rb.setActiontype(RequestInfoBean.REQUEST_ACTION);
	rb.setObjectname(classification.getObjectname());
	rb.setObjectclassvalue(generatedNumber);
	rb.setObjectclasspath(parentClassPath);
	
	ArrayList aFixLabelDef = GenerationRuleHelper.getFixLabelDefinitions(pb);
	ArrayList selectedFixedLabels = new ArrayList();
	for(int i=0; i<aFixLabelDef.size(); i++){
		String strFixLabelDef = (String)aFixLabelDef.get(i);
		String selFixLabelValue = request.getParameter(strFixLabelDef);
		
		FixLabelDefinition label = new FixLabelDefinition();
		label.setFixLabelDefinition(strFixLabelDef);
		label.setFixLabelDefinitionName("");
		label.setFixLabelValue(selFixLabelValue);
		selectedFixedLabels.add(label);
	}
	rb.setSelectedFixedLabels(selectedFixedLabels);
	
	//Get Rule
	RuleInfoContained rule = GenerationRuleHelper.getRule(rb, pb);

	NumberGenerator generator = new NumberGenerator(classification,rule,rb);
	FormatedNumber fnumber = generator.generateNumber();
	
	String gnumber = fnumber.getValue();
	String classpath = fnumber.getClassification().getObjectclasspath();
%>
	<script>window.opener.document.getElementById('parentPath').value='<%=classpath%>'</script>
	<script>window.opener.document.getElementById('fullPath').value='<%=fullClassPath%>'</script>
	<script>window.opener.document.getElementById('gnumber').value='<%=gnumber%>'</script>
	<script>window.opener.document.getElementById('objectname').value='<%=classification.getObjectname()%>'</script>
	<script>window.opener.document.getElementById('requestvolumn').value='1'</script>
	<script>
		window.open('','_self');  
		window.opener=null;
		window.close();
	</script>
	